package com.frame.work.frame.deal.device0fe6;

import com.alibaba.fastjson.JSONObject;
import com.frame.work.common.util.JsonToMqtt;
import com.frame.work.frame.deal.base.BaseFrame;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

import static com.frame.work.common.constant.CallType.*;
import static java.lang.Integer.parseInt;

/**
 *平移开窗器
 */
@Data
public class PingYiKaiChuangQi_0FE60211 extends BaseFrame {


    public PingYiKaiChuangQi_0FE60211(String gatewayMac, String data,String type) {

        //将基础数据进行处理
        super(gatewayMac, data);

        //根据不同类型进行判断
        if(TYPE_UP.equals(type)){
            PingYiKaiChuangQi_0FE60211_up(gatewayMac,data);
        }else if (TYPE_CONTROL.equals(type)){
            PingYiKaiChuangQi_0FE60211_control(gatewayMac,data);
        }



    }
    public void PingYiKaiChuangQi_0FE60211_up(String gatewayMac, String data){
        //处理此设备特有的数据


        //将actions信息放入json对象中
        Map<String, Object> actions = new HashMap();

        this.setActions(actions);


        //处理好的json对象
        String json = JSONObject.toJSONString(this);
        //将数据发送到mqtt队列中
        JsonToMqtt.sendMQTT(gatewayMac, json);
    }

    public void PingYiKaiChuangQi_0FE60211_control(String gatewayMac, String data) {

        //将基础数据进行处理
        this.setGatewayMac(gatewayMac);
        this.setDeviceMac(StringUtils.substring(data, 2, 18));
        this.setOdIndex(StringUtils.substring(data, 18, 22));
        this.setDeviceType(StringUtils.substring(data, 22, 24));
        this.setProductType(StringUtils.substring(data, 24, 26));

        String position = StringUtils.substring(data, data.length() - 4, data.length() - 2);
        if (parseInt(position, 16) <= 10) {


            //将actions信息放入json对象中
            Map<String, Object> actions = new HashMap();
            actions.put("position", position);

            this.setActions(actions);


            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac, json);
        }


    }

}
